package com.such.kit.datastructure.tree.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author SUCH
 * <pre>
 * 树节点
 * </pre>
 */
public class Node<T> implements Serializable {

	private static final long serialVersionUID = -6133975850323875675L;

	private String id;
	private String parentId;
	/** idPath：id 路径，格式：/rootId/id1/id2/id3 ... /this.id */
	private String idPath;
	/** level：节点所在的级别，下标从 1 开始 */
	private Integer level;
	private String title;
	private T nodeObject;
	private Map<String, Node<T>> childStore = new LinkedHashMap<String, Node<T>>();

	public Node(String id, String parentId, String title) {
		this.id = id;
		this.parentId = parentId;
		this.title = title;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getParentId() {
		return this.parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getIdPath() {
		return this.idPath;
	}

	public void setIdPath(String idPath) {
		this.idPath = idPath;
	}

	public Integer getLevel() {
		return this.level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public T getNodeObject() {
		return this.nodeObject;
	}

	public void setNodeObject(T nodeObject) {
		this.nodeObject = nodeObject;
	}

	public Map<String, Node<T>> getChildStore() {
		return this.childStore;
	}

	public void setChildStore(Map<String, Node<T>> childStore) {
		this.childStore = childStore;
	}

	public void addChild(Node<T> child) {
		this.childStore.put(child.getId(), child);
	}

	public void remodeChild(String  id) {
		this.childStore.remove(id);
	}

	public List<Node<T>> getChildren() {
		return new ArrayList<Node<T>>(this.childStore.values());
	}

}
